package com.jimo.transadb;


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.core.app.RemoteInput;

import com.jimo.transadb.bean.MessageEvent;
import com.jimo.transadb.utils.NotificationUtils;

import org.greenrobot.eventbus.EventBus;

public class InputPairReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
        if (remoteInput != null) {
            CharSequence text = remoteInput.getCharSequence(Constant.notifyIdName);
            if (text != null) {
                NotificationUtils.dismissNotifyByChannelId(Constant.channelId);
                if (intent.getBooleanExtra("isIpAddress", false)) {
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.BUS_PARE_ADDRESS, text));
                } else {
                    EventBus.getDefault().post(new MessageEvent(MessageEvent.BUS_PARE_CODE, text));
                }
            }
        }
    }
}